#include "rectCell.hpp"
#include "rectMesh.hpp"
#include "util.hpp"

namespace hms
{

RectCell::RectCell( const RectMesh& mesh, Index index ) :
	StructCellBase( mesh, index )
{}

RectCell::RectCell( const RectMesh& mesh, Index x, Index y ) :
	StructCellBase( mesh, x, y )
{}



auto RectCell::areaImp() const -> scalar {
	#ifdef RECTMESH_PRECALC_AREAS
		return m_mesh.cells().areas()(m_index);
	#else
		static constexpr Index ng { 1 };
		return
			m_mesh.dx()[ng + m_i] *
			m_mesh.dy()[ng + m_j];
	#endif
}

auto RectCell::circumfImp() const -> scalar {
	#ifdef RECTMESH_PRECALC_CIRCUMFS
		return m_mesh.cells().circumfs()(m_index);
	#else
		static constexpr Index ng { 1 };
		return 2 * (
			m_mesh.dx()[ng + m_i] +
			m_mesh.dy()[ng + m_j]
		);
	#endif
}

auto RectCell::centroidImp() const -> CentroidType {
	#ifdef RECTMESH_PRECALC_CENTROIDS
		return m_mesh.cells().centroids().col(m_index);
	#else
		static constexpr Index ng {1};
		return {
			m_mesh.cells().xCoords()( m_i + ng ),
			m_mesh.cells().yCoords()( m_j + ng )
		};
	#endif
}

} // namespace hms
